home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / PowerPC / Dev / PPCRelease / Examples / Timer / PPCTimer.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-06  |  5.9 KB  |  237 lines

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <utility/tagitem.h>
  6. #include <powerup/ppclib/interface.h>
  7. #include <powerup/ppclib/time.h>
  8. #include <powerup/gcclib/powerup_protos.h>
  9.  
  10. double    Test=66346667;
  11.  
  12. int    main(void)
  13. {
  14. long long        Result;
  15. long long        Ticks;
  16. long long        TicksPerSec;
  17. void            *MyTimerObject;
  18. void            *MyTimerJob;
  19. ULONG            b;
  20. int            i;
  21. struct TagItem        MyTags[4];
  22. ULONG            MySignal;
  23.  
  24.   MyTags[0].ti_Tag    =    PPCTIMERTAG_CPU;
  25.   MyTags[0].ti_Data    =    TRUE;
  26.   MyTags[1].ti_Tag    =    TAG_END;
  27.   if (MyTimerObject=PPCCreateTimerObject(MyTags))
  28.   {
  29.     PPCSetTimerObject(MyTimerObject,
  30.                       PPCTIMERTAG_START,
  31.                       NULL);
  32.  
  33. /* Do something silly
  34.  * to get the context switch delay
  35.  */
  36.     PPCOutput();
  37.  
  38.     PPCSetTimerObject(MyTimerObject,
  39.                       PPCTIMERTAG_STOP,
  40.                       NULL);
  41.  
  42.     PPCGetTimerObject(MyTimerObject,
  43.                       PPCTIMERTAG_TICKSPERSEC,
  44.                       &TicksPerSec);
  45.  
  46.     PPCprintf("TicksPerSec %Ld\n",TicksPerSec);
  47.  
  48.  
  49.  
  50.     PPCGetTimerObject(MyTimerObject,
  51.                       PPCTIMERTAG_START,
  52.                       &Result);
  53.  
  54.     PPCprintf("StartTicks 0x%Lx\n",Result);
  55.  
  56.     PPCGetTimerObject(MyTimerObject,
  57.                       PPCTIMERTAG_STOP,
  58.                       &Result);
  59.  
  60.     PPCprintf("StopTicks 0x%Lx\n",Result);
  61.  
  62.  
  63.  
  64.     PPCGetTimerObject(MyTimerObject,
  65.                       PPCTIMERTAG_CURRENTTICKS,
  66.                       &Result);
  67.     PPCprintf("Current 0x%Lx\n",Result);
  68.  
  69.  
  70.  
  71.     PPCGetTimerObject(MyTimerObject,
  72.                       PPCTIMERTAG_DIFFTICKS,
  73.                       &Result);
  74.     PPCprintf("DiffTicks %Ld\n",Result);
  75.  
  76.  
  77.     PPCprintf("PPCOutput() context switch took %4g seconds\n",
  78.               (((double) (Result) / (double)TicksPerSec)));
  79.  
  80.     PPCGetTimerObject(MyTimerObject,
  81.                       PPCTIMERTAG_DIFFMICRO,
  82.                       &Result);
  83.     PPCprintf("DiffMicro %Ld\n",Result);
  84.  
  85.  
  86.     PPCGetTimerObject(MyTimerObject,
  87.                       PPCTIMERTAG_DIFFSECS,
  88.                       &Result);
  89.     PPCprintf("DiffSecs %Ld\n",Result);
  90.  
  91.  
  92.     PPCGetTimerObject(MyTimerObject,
  93.                       PPCTIMERTAG_DIFFMINS,
  94.                       &Result);
  95.     PPCprintf("DiffMins %Ld\n",Result);
  96.  
  97.  
  98.     PPCGetTimerObject(MyTimerObject,
  99.                       PPCTIMERTAG_DIFFHOURS,
  100.                       &Result);
  101.     PPCprintf("DiffHours %Ld\n",Result);
  102.  
  103.  
  104.     PPCGetTimerObject(MyTimerObject,
  105.                       PPCTIMERTAG_DIFFDAYS,
  106.                       &Result);
  107.     PPCprintf("DiffDays %Ld\n",Result);
  108.  
  109.  
  110.     PPCprintf("Use 50Hz Timer to wait 4 seconds\n");
  111.  
  112.     if ((MySignal=PPCAllocSignal(-1)) != -1)
  113.     {
  114.       MyTags[0].ti_Tag    =    PPCTIMERTAG_50HZ;
  115.       MyTags[0].ti_Data    =    50*4;
  116.       MyTags[1].ti_Tag    =    PPCTIMERTAG_SIGNALMASK;
  117.       MyTags[1].ti_Data    =    1<<MySignal;
  118.       /* Remove the job out of the timer notify list
  119.        * after the signal
  120.        */
  121.       MyTags[2].ti_Tag    =    PPCTIMERTAG_AUTOREMOVE;
  122.       MyTags[2].ti_Data    =    TRUE;
  123.       MyTags[3].ti_Tag    =    TAG_END;
  124.  
  125.       PPCSetTimerObject(MyTimerObject,
  126.                         PPCTIMERTAG_START,
  127.                         NULL);
  128.  
  129.       if (MyTimerJob=PPCCreateTimerObject(MyTags))
  130.       {
  131.         PPCWait(1<<MySignal);
  132.         PPCSetTimerObject(MyTimerObject,
  133.                           PPCTIMERTAG_STOP,
  134.                           NULL);
  135.  
  136.         PPCprintf("notification received\n");
  137.  
  138.         PPCprintf("Restart 4 second timers\n");
  139.  
  140.         PPCSetTimerObject(MyTimerObject,
  141.                           PPCTIMERTAG_START,
  142.                           NULL);
  143.  
  144.         PPCSetTimerObject(MyTimerJob,
  145.                           PPCTIMERTAG_START,
  146.                           NULL);
  147.  
  148.         PPCWait(1<<MySignal);
  149.         PPCSetTimerObject(MyTimerObject,
  150.                           PPCTIMERTAG_STOP,
  151.                           NULL);
  152.  
  153.         PPCprintf("notification received\n");
  154.  
  155.         PPCDeleteTimerObject(MyTimerJob);
  156.  
  157.  
  158.         PPCprintf("Use new 50Hz Timer to wait again 4 seconds\n");
  159.  
  160.         PPCSetTimerObject(MyTimerObject,
  161.                           PPCTIMERTAG_START,
  162.                           NULL);
  163.  
  164.         if (MyTimerJob=PPCCreateTimerObject(MyTags))
  165.         {
  166.           PPCWait(1<<MySignal);
  167.           PPCSetTimerObject(MyTimerObject,
  168.                             PPCTIMERTAG_STOP,
  169.                             NULL);
  170.  
  171.           PPCprintf("notification received\n");
  172.           PPCDeleteTimerObject(MyTimerJob);
  173.         }
  174.  
  175.  
  176.  
  177.  
  178.  
  179.         PPCGetTimerObject(MyTimerObject,
  180.                           PPCTIMERTAG_DIFFTICKS,
  181.                           &Ticks);
  182.  
  183.         PPCprintf("DiffTicks %Ld\n",Ticks);
  184. #if 0
  185. //        asm("twi 31,0,0");
  186.         PPCprintf("waited for %g(float) seconds\n",
  187.                   ((double) Ticks) / (double) TicksPerSec);
  188. #else
  189.         PPCprintf("waited for %g %g %g(float) %ld(int) seconds\n",
  190.                   (double) 66346667,
  191.                   (double) Ticks,
  192.                   ((double) Ticks) / (double) TicksPerSec,
  193.                   Ticks / TicksPerSec);
  194. #endif
  195.  
  196.         PPCGetTimerObject(MyTimerObject,
  197.                           PPCTIMERTAG_DIFFMICRO,
  198.                           &Result);
  199.         PPCprintf("DiffMicro %Ld\n",Result);
  200.  
  201.  
  202.         PPCGetTimerObject(MyTimerObject,
  203.                           PPCTIMERTAG_DIFFSECS,
  204.                           &Result);
  205.         PPCprintf("DiffSecs %Ld\n",Result);
  206.  
  207.  
  208.         PPCGetTimerObject(MyTimerObject,
  209.                           PPCTIMERTAG_DIFFMINS,
  210.                           &Result);
  211.         PPCprintf("DiffMins %Ld\n",Result);
  212.  
  213.  
  214.         PPCGetTimerObject(MyTimerObject,
  215.                           PPCTIMERTAG_DIFFHOURS,
  216.                           &Result);
  217.         PPCprintf("DiffHours %Ld\n",Result);
  218.  
  219.  
  220.         PPCGetTimerObject(MyTimerObject,
  221.                           PPCTIMERTAG_DIFFDAYS,
  222.                           &Result);
  223.         PPCprintf("DiffDays %Ld\n",Result);
  224.  
  225.       }
  226.       PPCFreeSignal(MySignal);
  227.     }
  228.     else
  229.     {
  230.       PPCprintf("Couldn`t alloc Signal\n");
  231.     }
  232.  
  233.     PPCDeleteTimerObject(MyTimerObject);
  234.   }
  235. }
  236.  
  237.